//
//  ShellTotalRewardCell.m
//  ShellWallert
//
//  Created by lvzhao on 2019/10/3.
//  Copyright © 2019 VV. All rights reserved.
//

#import "ShellTotalRewardCell.h"
#import "ShellTotalRewardModel.h"

@interface ShellTotalRewardCell()

//icon
@property (nonatomic,strong) UIImageView *iconImageView;

//数量
@property (nonatomic,strong) UILabel *numberLab;

//类型
@property (nonatomic,strong) UILabel *typeLabel;

//时间
@property (nonatomic,strong) UILabel *timeLabel;



@end

@implementation ShellTotalRewardCell

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        self.accessoryType  = UITableViewCellAccessoryNone;
        
        self.backgroundColor = UIColorHex(0x08233F);
        [self setupView];
    }
    return self;
}


#pragma mark - setupView
- (void)setupView{
    
    //类型
    [self.contentView addSubview:self.typeLabel];
    [self.typeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(self.contentView.mas_centerY);
        make.left.mas_equalTo(0);
        make.width.mas_equalTo(150);
        make.height.mas_equalTo(17);
    }];
    
    
    //数量
    [self.contentView addSubview:self.numberLab];
    [self.numberLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(self.contentView.mas_centerY);
        make.left.mas_equalTo(self.typeLabel.mas_right).mas_offset(10);
        make.width.mas_equalTo(115);
        make.height.mas_equalTo(17);
    }];
  
    //时间
    [self.contentView addSubview:self.timeLabel];
    [self.timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(self.contentView.mas_centerY);
        make.right.mas_equalTo(0);
        make.width.mas_equalTo(80);
        make.height.mas_equalTo(17);
    }];

    
}


#pragma mark - actions

#pragma mark - custool

#pragma mark - get && set
- (void)setModelObject:(id)modelObject{
    ShellTotalRewardModel *rewardModel = modelObject;
    NSString *amount = [NSString stringWithFormat:@"%f",rewardModel.amount].scientific;
    self.numberLab.text = [NSString stringWithFormat:@"+%@ USDT",amount];
    self.typeLabel.text = LZLocalizedString(@"矿池奖励");
    CGFloat typeWidth = [self.typeLabel.text lz_textWidthWithFontSize: self.typeLabel.font withMaxHeight:17];
    [self.typeLabel mas_updateConstraints:^(MASConstraintMaker *make) {
        make.width.mas_equalTo(typeWidth);
    }];
    self.timeLabel.text = [self compareCurrentTime:rewardModel.createTime];
}

- (NSString *) compareCurrentTime:(NSString *)str{

//把字符串转为NSdate

    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];

    [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];

    NSDate *timeDate = [dateFormatter dateFromString:str];

    //得到与当前时间差

    NSTimeInterval  timeInterval = [timeDate timeIntervalSinceNow];

    timeInterval = -timeInterval;

    long temp = 0;

    NSString *result;

    if(timeInterval < 60){
        
        result = [NSString stringWithFormat:LZLocalizedString(@"%ld秒前"),2];
        
    } else if((temp = timeInterval/60) <60){

        result = [NSString stringWithFormat:LZLocalizedString(@"%ld分钟前"),temp];

    }

    else if((temp = temp/60) <24){

        result = [NSString stringWithFormat:LZLocalizedString(@"%ld小时前"),temp];

    }

    else if((temp = temp/24) <30){
        result = [NSString stringWithFormat:LZLocalizedString(@"%ld天前"),temp];
    }

    else {

        result = [NSString stringWithFormat:LZLocalizedString(@"%ld月前"),temp];

    }


    return  result;

}





//数量
- (UILabel *)numberLab{
    if(!_numberLab){
        _numberLab = [UILabel lz_createLabWithTextColor:UIColorHex(0x64E3AE) font:k_textFont(12)];
        _numberLab.adjustsFontSizeToFitWidth = YES;
    }
    return _numberLab;
}


//类型
- (UILabel *)typeLabel{
    if(!_typeLabel){
        _typeLabel = [UILabel lz_createLabWithTextColor:UIColorHex(0xFFFFFF) font:k_textFont(12)];
        _typeLabel.numberOfLines = 0;
        _typeLabel.adjustsFontSizeToFitWidth = YES;
    }
    return _typeLabel;
}

//时间
- (UILabel *)timeLabel{
    if(!_timeLabel){
        _timeLabel = [UILabel lz_createLabWithTextColor:UIColorHex(0x8D99B2) font:k_textFont(12)];
        [_timeLabel lz_rightAlignment];
    }
    return _timeLabel;
}

//
////地址
//- (UILabel *)addressLab{
//    if(!_addressLab){
//        _addressLab = [UILabel lz_createLabWithTextColor:UIColorHex(0xFFFFFF) font:k_textFont(12)];
//    }
//    return _addressLab;
//}
//
////状态
//- (UILabel *)statusLab{
//    if(!_statusLab){
//        _statusLab = [UILabel lz_createLabWithTextColor:UIColorHex(0xF4376D) font:k_textFont(12)];
//        [_statusLab lz_centerAlignment];
//    }
//    return _statusLab;
//}
//
////时间
//- (UIButton *)timeBtn{
//    if(!_timeBtn){
//        _timeBtn = [UIButton lz_buttonTitle:@"" titleColor:UIColorHex(0x4AB2E7) fontSize:12];
//        [_timeBtn setImage:k_imageName(@"icon_order_time") forState:UIControlStateNormal];
//    }
//    return _timeBtn;
//}
//
//- (UIImageView *)lineView{
//    if (!_lineView) {
//        _lineView = [[UIImageView alloc] initWithImage:k_imageName(@"icon_xuxian")];
//    }
//    return _lineView;
//}   


@end
